<?php
namespace App\Service\Pay;

class Response extends Base
{
    // 响应数据
    protected $data = [];
    
    public function __construct($data)
    {
        $this->data = $data;
    }
    
    // 是否出错
    public function error()
    {
        if(!$this->data)
        {
            return true;
        }
        
        return $this->data['errCode'] <> 'SUCCESS';
    }
    
    // 错误信息
    public function message()
    {
        if(!$this->data)
        {
            return 'Error';
        }
        
        if($this->error())
        {
            return $this->data['errMsg'];
        }
    }

    // 获取数据
    public function data($key = null)
    {
        return $key ? $this->data[$key] : $this->data;
    }
}